feat(agent-composer): add message identity and queue cancel APIs - #5537
Conversation
Code Review SummaryStatus: No Issues Found | Recommendation: Merge Files Reviewed (25 files)
Previous Review Summaries (2 snapshots, latest commit c347899)Current summary above is authoritative. Previous snapshots are kept for context only. Previous review (commit c347899)Status: 2 Issues Found | Recommendation: Address before merge Fix these issues in Kilo Cloud Overview
Issue Details (click to expand)WARNING
Files Reviewed (24 files)
Previous review (commit 445fe65)Status: 2 Issues Found | Recommendation: Address before merge Fix these issues in Kilo Cloud Overview
Issue Details (click to expand)WARNING
Files Reviewed (24 files)
Reviewed by grok-4.6 · Input: 149.4K · Output: 12.9K · Cached: 321.7K Review guidance: REVIEW.md from base branch |
# Conflicts: # services/session-ingest/src/dos/UserConnectionDO.ts
|
@iscekic from what I remember cancellation is possible only while message is not sent to Kilo. For example when sandbox is being prepared. In all other cases a message is sent to Kilo and I'm not sure if we can cancel it at that moment |
|
@eshurakov Correct. |
Summary
SessionMessageQueue.cancelQueuedMessagedrops only queued work, repairs legacy state when possible, and leaves accepted or terminal messages untouched.SessionMessageCompletionSourceSchemaaddscanceled, keeping canceled IDs terminal, rejecting readmission, and excluding them from reconnect catch-up. Retries after completed cancellation return{ dropped: true }soCloudAgentSessioncan persist onecloud.message.canceledevent; unknown IDs return{ dropped: false }.Files
services/cloud-agent-next/src/session/session-message-queue.ts— modified source; 56 changed lines; records cancellation before deleting the pending row, without scheduling acloud.message.failedevent.services/cloud-agent-next/src/session/session-message-state.ts— modified source; 1 changed line; acceptscanceledas a completion source without changing existing states.services/cloud-agent-next/src/persistence/CloudAgentSession.ts— modified source; 36 changed lines; stores and broadcasts a unique cancellation event for live delivery and replay.services/cloud-agent-next/src/session/session-message-queue.test.ts— modified test; 106 changed lines; expands the message queue tests.services/cloud-agent-next/test/integration/session/pending-messages.test.ts— modified test; 85 changed lines; expands the pending-message integration tests.The personal and organization
cancelQueuedMessagemutations return{ dropped: boolean }after ownership checks; organization calls also require membership.baseCancelQueuedMessageNextSchemaandCancelQueuedMessageInputcarrysessionIdand a canonicalmessageId; organization requests also requireorganizationId.CloudAgentNextTRPCClient.cancelQueuedMessageforwards authenticated requests; the worker validatesMessageIdSchema, rechecks current access, and retries the Durable Object call.Files
apps/web/src/lib/cloud-agent-next/cloud-agent-client.ts— modified source; 29 changed lines; adds the cancellation input, typed mutation, and client method with error reporting and propagation.apps/web/src/routers/cloud-agent-next-router.ts— modified source; 17 changed lines; adds cancellation with personal ownership checks and a boolean result.apps/web/src/routers/cloud-agent-next-schemas.ts— modified source; 6 changed lines; requires the canonical message ID for cancellation requests.apps/web/src/routers/organizations/organization-cloud-agent-next-router.ts— modified source; 25 changed lines; adds organization-scoped cancellation with membership and ownership checks.services/cloud-agent-next/src/router/handlers/session-management.ts— modified source; 45 changed lines; adds guarded cancellation with durable retries and removes a comment spacer.apps/web/src/routers/cloud-agent-next-router.test.ts— modified test; 29 changed lines; updates the personal router tests.apps/web/src/routers/cloud-agent-next-schemas.test.ts— modified test; 23 changed lines; updates the request-schema tests.apps/web/src/routers/organizations/organization-cloud-agent-next-router.test.ts— modified test; 35 changed lines; updates the organization router tests.The software development kit (SDK) adds
CloudAgentSession.cancelQueuedMessageandSessionManager.cancelQueuedMessagethrough optionalTransport.dropQueuedMessageandCloudAgentApi.cancelQueuedMessagehooks. Legacy providers remain compatible; unsupported calls fail without interrupting, and the manager does nothing without an active session.ServiceEventandcloudMessageCanceledDataSchemavalidatecloud.message.canceled, which removes the pending entry and local message and invokesonMessageCanceledthroughServiceStateConfigandCloudAgentSessionConfig.Files
packages/cloud-agent-sdk/src/transport.ts— modified source; 16 changed lines; adds optional cancellation contracts so existing transports and providers still compile.packages/cloud-agent-sdk/src/cloud-agent-transport.ts— modified source; 6 changed lines; binds cancellation to the cloud session and rejects calls without the provider hook.packages/cloud-agent-sdk/src/session-manager.ts— modified source; 12 changed lines; delegates cancellation and passes errors through without falling back to interruption.packages/cloud-agent-sdk/src/session.ts— modified source; 14 changed lines; exposes cancellation and its callback, then deletes the local message when the cancellation event arrives.packages/cloud-agent-sdk/src/normalizer.ts— modified source; 23 changed lines; validates cancellation events with a message ID and an optional execution ID.packages/cloud-agent-sdk/src/service-state.ts— modified source; 13 changed lines; removes the pending entry, invokes the cancellation callback, and notifies subscribers.packages/cloud-agent-sdk/src/cloud-agent-transport.test.ts— modified test; 15 changed lines; updates the cloud transport tests.packages/cloud-agent-sdk/src/session-manager.test.ts— modified test; 18 changed lines; updates the session manager tests.packages/cloud-agent-sdk/src/session-transport.test.ts— modified test; 32 changed lines; updates the session transport tests.send_messagenow includesmessageIDwhen the caller supplies one, keeping queued turns tied to the caller's identity.drop_queued_messagesends{ protocolVersion: 1, messageID }to the current owner, and the relay permits that command. Calls without a message ID keep the old send shape; unsupported remotes returnCLI_UPGRADE_REQUIREDrather than triggeringinterrupt.Files
packages/cloud-agent-sdk/src/cli-live-transport.ts— modified source; 6 changed lines; forwards prompt identity and sends the cancellation command to the current owner.services/session-ingest/src/dos/UserConnectionDO.ts— modified source; 4 changed lines; allows cancellation and maps the exact unsupported-command reply to the upgrade-required error.packages/cloud-agent-sdk/src/cli-live-transport.test.ts— modified test; 68 changed lines; updates the remote transport tests.Tests: 9 test files modified, totaling 411 changed lines across the named router, schema, transport, session, queue, and integration tests.
Generated: 0 files changed.
Visual Changes
Visual Changes: N/A
Verification
E2E report not attached. Runtime verification (E2E, user advocacy, simplify) runs on the tip PR over every level of this 6-level stack, so this level carries no manual verification.
The cumulative report belongs to tip PR 5617.
Human steps
drop_queued_message.No new environment values, secrets, database migrations, or data backfills are required.
Reviewer Notes
This is level 1 of a 6-level stacked set of PRs. Merge bottom to top. Runtime verification (E2E, user advocacy, simplify) runs on the tip PR over every level.
Cumulative runtime verification and its limits are recorded in #5617.
Current-head CI and Kilobot approve this PR.
This level adds message identity and cancellation contracts, without new interface controls or the remote sender implementation.
The comparison contains 25 modified files: 16 source files and 9 test files, with 717 insertions and 3 deletions. Each file size counts changed lines from the supplied statistics, not its full length.
Kilo-Org/cloud/Users/igor/Projects/.worktrees/agent-composers-c07aorigin/main...5b47fbea5fd57ceb366bc033e094bf8906f6c53c; the checkout is onagent-composers-c07a-s6.Kilo-Org/kilocode/Users/igor/Projects/.worktrees/agent-composers-c07a-kilocodeagent-composers-c07a; remote sender PR 13496.Stacked PRs — merge bottom to top. Each level shows only its own diff.
Runtime verification (E2E, user advocacy, simplify) runs on the tip PR over every level.
Every level keeps its own checks, its own bot review, and its own threads; each one is answered on its own PR.
Each level is its own deliverable: it builds and passes its own checks alone.
A finding on a level is repaired on that level, then carried upward with stack.sh forward.
agent-composers-c07a— feat(agent-composer): add message identity and queue cancel APIs #5537agent-composers-c07a-s2— feat(mobile): pre-upload attachments and release abandoned files #5538agent-composers-c07a-s3— feat(mobile): reorder composer attachments with drag and a11y moves #5540agent-composers-c07a-s4— feat(agent-composer): render sent messages immediately and cancel queued ones #5589agent-composers-c07a-s5— feat(mobile): keep agent composers editable during live dictation #5607agent-composers-c07a-s6— feat(mobile): adapt agent composers for keyboard, height, and preferences #5617 (tip)